﻿/*
 页面参数
 */
var currentIndex=1,pageSize=15,urllot="",urllat="",readyover=0;

/*
 页面返回 回主页
 */
$("#logo").click(function(){
    location.href="pulu.html"
});

/*
 时间
 */
function getDateTimeStamp(dateStr){
    dateStr=dateStr.match(/[0-9\-T\:]+/)[0].replace(/T/g,' ');
    return Date.parse(dateStr.replace(/-/gi,"/"));
}
function getDateDiff(dateTimeStamp){
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = now - dateTimeStamp;
    if(diffValue < 0){ result="刚刚";return;}
    var monthC =diffValue/month;
    var weekC =diffValue/(7*day);
    var dayC =diffValue/day;
    var hourC =diffValue/hour;
    var minC =diffValue/minute;
    if(monthC>=1){result="" + parseInt(monthC) + "月前";}
    else if(weekC>=1){result="" + parseInt(weekC) + "周前";}
    else if(dayC>=1){result=""+ parseInt(dayC) +"天前";}
    else if(hourC>=1){result=""+ parseInt(hourC) +"小时前";}
    else if(minC>=1){result=""+ parseInt(minC) +"分钟前";}
    else result="刚刚";
    return result;
}

/*
 加载图片
 */
function showloadimg(e){
    $(e).fadeIn();
}

/*
 搜索
 */
$("#gotosearch").click(function(){
    if($.cookie("MYID")){
        $.cookie("searchPageCurrentIndex","");//搜索定位
        $.cookie("searchPageTop","");
        $.cookie("searchType","");
        location.href="searchdetail.html";
    }
});

/*
 修复PC https http cookie 判断用户
 */
//没有来源网址的全部去登录
if(!document.referrer){
    location.href="http://www.pulu.com/weixin/login.html";
}else{
    if(!$.cookie("MYID")){ //没有用户去登录
        location.href="http://www.pulu.com/weixin/login.html";
    }
}


if(localStorage.getItem("MYID")){
    id=localStorage.getItem("MYID");
    $.cookie("MYID",localStorage.getItem("MYID"));
}
if($.cookie("MYID")){id=$.cookie("MYID")}

//pc自动登录
if(!is_weixn()){
    if(localStorage.getItem("MYID")){
        $.cookie("MYID",localStorage.getItem("MYID"));
        id=localStorage.getItem("MYID");
    }
}

/*
 判断类型 展示菜单栏
 */
var originType=["single","progect","other"];//单身...
//经验的类型为纯数字
if(/type=[0-9]+/.test(location.href)){
    $(".quick").css("display","block");
    $.ajax({
        type:"get",
        url:"https://www.pulu.com/webapi/api/Pulu_fltype/Getpulu_fltype",
        success:function(d){
            $(d.Data).each(function(){
                if(!$.cookie("selectType")){
                    var typeId=location.href.match(/type=[0-9]+/)[0].split("=")[1];
                    if(this.id==typeId){
                        $.cookie("selectType",typeId);
                        $("#page_title .title").html(this.name);
                        $("#page_title .select").append("<div class='option active' data-num='"+this.id+"'>"+this.name+"</div>");
                    }
                    else{
                        $("#page_title .select").append("<div class='option' data-num='"+this.id+"'>"+this.name+"</div>");
                    }
                }
                else{
                    if(this.id==$.cookie("selectType")){
                        //console.log($.cookie("selectType"));
                        $("#page_title .title").html(this.name);
                        $("#page_title .select").append("<div class='option active' data-num='"+this.id+"'>"+this.name+"</div>");
                    }
                    else{
                        $("#page_title .select").append("<div class='option' data-num='"+this.id+"'>"+this.name+"</div>");
                    }
                }
            })
        }
    });
}
//单身资源...
else if(/type=[a-zA-Z]+/.test(location.href)){
    $(".quick").css("display","none");
    $("div.wrapper.home_feed").css("padding-bottom","0");
    var thisTypeName=location.href.match(/type=[a-zA-Z]+/)[0].split("=")[1];
    if(!$.cookie("selectType")){$.cookie("selectType",thisTypeName)}else{thisTypeName=$.cookie("selectType")};
    thisTypeName=="single"?$("#page_title .title").html("单身资源"):thisTypeName=="work"?$("#page_title .title").html("工作介绍"):thisTypeName=="house"?$("#page_title .title").html("租房买房"):thisTypeName=="progect"?$("#page_title .title").html("项目资源"):thisTypeName=="resource"?$("#page_title .title").html("人脉资源"):thisTypeName=="other"?$("#page_title .title").html("其他资源"):"";
    for(var i=0;i<originType.length;i++){
        var activeStype="";
        if(originType[i]==thisTypeName){activeStype=" active";}
        var typeName="";
        originType[i]=="single"?typeName="单身资源":originType[i]=="work"?typeName="工作介绍":originType[i]=="house"?typeName="租房买房":originType[i]=="progect"?typeName="项目资源":originType[i]=="resource"?typeName="人脉资源":originType[i]=="other"?typeName="其他资源":"";
        $("#page_title .select").append("<div class='option"+activeStype+"' data-num='"+originType[i]+"'>"+typeName+"</div>");
    }
}
else{

    $.cookie("selectType",1);
}

/*
 * 保存跳转页码 距离
 */
function savepage(){
    var scrollTop=$(window).scrollTop();
    $.cookie("jyscrollTop",scrollTop);
    $.cookie("jycurrentIndex",currentIndex);
}

/*
 跳转方法
 */
//跳转经验类别
function goexptype(d){
    //取消事件冒泡
    var e=arguments.callee.caller.arguments[0]||event;
    if (e && e.stopPropagation) {
        e.stopPropagation();
    } else if (window.event) {
        window.event.cancelBubble = true;
    }
    savepage();//保存页码 距离
    readyover=0;
    if(/^[0-9]+$/.test(d.dataset.type)){
        switch(parseInt(d.dataset.type)){
            case 1:$.cookie("selectType","");location.href="questionlistjy.html?type=1";break;//吃亏
            case 2:$.cookie("selectType","");location.href="questionlistjy.html?type=2";break;//划算
            case 3:$.cookie("selectType","");location.href="questionlistjy.html?type=3";break;//新奇
            case 4:$.cookie("selectType","");location.href="questionlistjy.html?type=4";break;//其他
            case 5:$.cookie("selectType","");location.href="questionlistjy.html?type=5";break;//电影
            case 6:$.cookie("selectType","");location.href="questionlistjy.html?type=6";break;//美食
            case 7:$.cookie("selectType","");location.href="questionlistjy.html?type=7";break;//旅游
            case 8:$.cookie("selectType","");location.href="questionlistjy.html?type=8";break;//读书
            case 22:
                $.cookie("selectType","");
                if(!is_weixn){location.href="questionlistjy.html?type=22&id="+$.cookie("MYID")}
                else{location.href="questionlistjy.html?type=22"};
                break;//附近
            case 23:$.cookie("selectType","");location.href="questionlistjy.html?type=23";break;//人生
            case 24:$.cookie("selectType","");location.href="questionlistjy.html?type=24";break;//育儿
            case 25:$.cookie("selectType","");location.href="questionlistjy.html?type=25";break;//工作
            case 26:$.cookie("selectType","");location.href="questionlistjy.html?type=26";break;//健康
            case 27:$.cookie("selectType","");location.href="questionlistjy.html?type=27";break;//购物
        }
    }else if(/^[a-z]+$/.test(d.dataset.type)){
        $.cookie("selectType","");
        readyover=0;
        location.href="questionlistjy.html?type="+d.dataset.type;
    }
}

/*
 点击用户头像
 */
function usergohref(e){
    var even=arguments.callee.caller.arguments[0]||event;
    if (even && even.stopPropagation) {
        even.stopPropagation();
    } else if (window.event) {
        window.event.cancelBubble = true;
    }
    if($.cookie("MYID")){
        savepage();
        var sendid="?otherid="+e.dataset.uid;
        if(!is_weixn()){sendid="?id="+$.cookie("MYID")+"&otherid="+e.dataset.uid;}
        if(e.dataset.uid==$.cookie("MYID")){
            location.href="setpage.html";
        }
        else{
            location.href="otherpeoplepage.html"+sendid;
        }
    }
}
function hrefgo(d){
    var url= d.dataset.href;
    savepage();//保存页码 距离
    //清除转发者信息 防止返回信息保存
    $.cookie("shareUserId","");
    $.cookie("fromuser","");
    var shareuserid="";
    if(d.dataset.shareuserid){
        //shareuser="&shareuser="+e.dataset.shareuserid;
        $.cookie("shareUserId",d.dataset.shareuserid);
        if($.cookie("selectType")==22&&!is_weixn()){
            shareuserid="#shareUserId="+d.dataset.shareuserid;
        }
    }
    location.href=url+shareuserid;
}

/*
 * 高德地图
 */
function mapftn(){
    //没有坐标信息
    if(!$.cookie("pululot")||!/[0-9]/.test($.cookie("pululot"))){
        var map, geolocation;
        //加载地图，调用浏览器定位服务
        map = new AMap.Map('mapplace', {
            resizeEnable: true
        });
        map.plugin('AMap.Geolocation', function() {
            geolocation = new AMap.Geolocation({
                enableHighAccuracy: true,//是否使用高精度定位，默认:true
                noIpLocate:0,
                GeoLocationFirst:true,//默认为false，设置为true的时候可以调整PC端为优先使用浏览器定位，失败后使用IP定位
                convert: true,         //自动偏移坐标，偏移后的坐标为高德坐标，默认：true
                timeout: 15000          //超过15秒后停止定位，默认：无穷大
            });
            map.addControl(geolocation);
            geolocation.getCurrentPosition();
            AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
            AMap.event.addListener(geolocation, 'error', onError);      //返回定位出错信息
        });
        //解析定位结果
        function onComplete(data) {
            var expiresDate= new Date();
            expiresDate.setTime(expiresDate.getTime() + (60 * 60 * 1000));
            //有效60分钟
            $.cookie("pululot",data.position.lng,{expires : expiresDate});
            $.cookie("pululat",data.position.lat,{expires : expiresDate});
            getallnote(currentIndex,pageSize);
        }
        //解析定位错误信息
        function onError(data) {
            $("#nonews").css("display","block");
            $("#waiting1").css("display","none");
            $("#nonews1").css("display","none");
        }
    }
    //保存坐标信息
    else{
        getallnote(currentIndex,pageSize);
    }
}

/*
 关键词列表页
 */
function gotoheiexp(data){
    var eid=data.dataset.keyword;
    var e=arguments.callee.caller.arguments[0]||event;
    var loca=location.href;
    if(e&&e.stopPropagation()){e.stopPropagation();}else if(window.event){window.event.cancelBubble = true;}
    savepage();//保存页码 距离
    //关键词列表页
    $.cookie("keywordtype","");
    $.cookie("keywordid","");
    $.cookie("kyscrollTop","");
    $.cookie("kycurrentIndex","");
    location.href="keywordslist.html?type="+data.dataset.qtype+"&eid="+eid;
    //$.cookie("expkeyword",eid);
    //$.cookie("expType","");
    //$.cookie("sendque","");
    //if(/[0-9]/.test($.cookie("selectType"))){
    //    $.cookie("selectType")==1?$.cookie("expType","chikui"):$.cookie("selectType")==2?$.cookie("expType","huasuan"):$.cookie("selectType")==3?$.cookie("expType","xinqi"):$.cookie("selectType")==5?$.cookie("expType","tuijiandy"):$.cookie("selectType")==6?$.cookie("expType","tuijianfd"):$.cookie("selectType")==7?$.cookie("expType","youwan"):$.cookie("selectType")==8?$.cookie("expType","shu"):$.cookie("selectType")==4?$.cookie("expType","qita"):$.cookie("selectType")==26?$.cookie("expType","jkjy"):$.cookie("selectType")==27?$.cookie("expType","gwjy"):$.cookie("selectType")==25?$.cookie("expType","gzjy"):$.cookie("selectType")==24?$.cookie("expType","yejy"):$.cookie("selectType")==23?$.cookie("expType","rensheng"):$.cookie("expType","");
    //    location.href="sendexpgpc.html";
    //}
    //else if(/[a-zA-Z]/.test($.cookie("selectType"))){
    //    $.cookie("selectType")=="single"?location.href="sendexpgpc.html?goSingle":$.cookie("selectType")=="work"?location.href="sendexpgpc.html?goWork":$.cookie("selectType")=="house"?location.href="sendexpgpc.html?goHouse":$.cookie("selectType")=="resource"?location.href="sendexpgpc.html?goRes":$.cookie("selectType")=="progect"?location.href="sendexpgpc.html?goProgect":$.cookie("selectType")=="other"?location.href="sendexpgpc.html?goOther":"";
    //}
}

/*
 发经验问题
 */
$(".quick").click(function(){
    savepage();//保存页码 距离
    if(is_weixn()){
        $.cookie("expkeyword","");
        $.cookie("expType","");
        $.cookie("sendque","");
        $.cookie("selectType")==1?$.cookie("expType","chikui"):$.cookie("selectType")==2?$.cookie("expType","huasuan"):$.cookie("selectType")==3?$.cookie("expType","xinqi"):$.cookie("selectType")==5?$.cookie("expType","tuijiandy"):$.cookie("selectType")==6?$.cookie("expType","tuijianfd"):$.cookie("selectType")==7?$.cookie("expType","youwan"):$.cookie("selectType")==8?$.cookie("expType","shu"):$.cookie("selectType")==4?$.cookie("expType","qita"):$.cookie("selectType")==26?$.cookie("expType","jkjy"):$.cookie("selectType")==27?$.cookie("expType","gwjy"):$.cookie("selectType")==25?$.cookie("expType","gzjy"):$.cookie("selectType")==24?$.cookie("expType","yejy"):$.cookie("selectType")==23?$.cookie("expType","rensheng"):$.cookie("expType","");
        location.href="http://www.pulu.com/weixin/sendexpgpc.html";
    }
    else{
        var expType="";
        $.cookie("selectType")==1?expType="&expType=chikui":$.cookie("selectType")==2?expType="&expType=huasuan":$.cookie("selectType")==3?expType="&expType=xinqi":$.cookie("selectType")==5?expType="&expType=tuijiandy":$.cookie("selectType")==6?expType="&expType=tuijianfd":$.cookie("selectType")==7?expType="&expType=youwan":$.cookie("selectType")==8?expType="&expType=shu":$.cookie("selectType")==4?expType="&expType=qita":$.cookie("selectType")==24?expType="&expType=yejy":$.cookie("selectType")==25?expType="&expType=gzjy":$.cookie("selectType")==27?expType="&expType=gwjy":$.cookie("selectType")==26?expType="&expType=jkjy":$.cookie("selectType")==23?expType="&expType=rensheng":expType="";
        location.href="https://www.pulu.com/weixin/sendexpgpc.html?id="+id+expType;
    }
});

/*
 经验方法
 */
function jy(d){
    //全部经验页 返回家在重复使用jyhaveajax进行判断 pulupagejy.js
    if(d.title&& d.title.length>0){
        //是不是推荐 真名
        var tuijianword="";
        var realName="";
        if(d.realName){realName=" ("+ d.realName+")"}
        if(d.isStranger===1|| d.isstanger===1){
            tuijianword="<i>系统推荐</i> ";
            //realName="";
        }
        //匿名
        var unick="";
        if(d.questionUserNick){
            if(d.ishidename==1){unick="<a>"+tuijianword+"匿名</a>";}else{unick="<a onclick='usergohref(this)' data-uid='"+d.questionUserId+"'>"+tuijianword+d.nick+realName+"</a>";}
        }
        //头像
        var uimgword="";
        if(d.questionUserAva){
            if(d.ishidename==1){
                uimgword="<a href='javascript: ;'><img class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)'></a>";
            }else{
                uimgword="<a onclick='usergohref(this)' data-uid='"+d.questionUserId+"'><img class='profile_photo_img' src='http://42.62.66.198:8003/"+d.questionUserAva+"' onload='showloadimg(this)' style='display:none;'></a>";
            }
        }else{
            if(d.ishidename==1){
                uimgword="<a href='javascript: ;'><img class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
            }else{
                uimgword="<a onclick='usergohref(this)' data-uid='"+d.questionUserId+"'><img onclick='gohrefftn(this)' class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
            }
        };
        //时间
        var tim="";
        if(d.shareTime){tim=getDateDiff(getDateTimeStamp(d.shareTime));}
        //有没有图片
        var haveimg="";
        if(d.imgcount>0||(d.qImgs&&d.qImgs.length>0)){haveimg="<span class='isheighlogo haveimg'></span>"}

        var logoImg="";
        var resTypeCode="";
        var resTypeName="";
        var keyTypeWord="的经验";
        if(d.qtype==4){
            logoImg=" singlelogo";
            resTypeCode="single";
            resTypeName="单身资源";
            keyTypeWord="的单身资源";
        }else if(d.qtype==6){
            logoImg=" singlelogo";
            keyTypeWord="的工作介绍";
        }else if(d.qtype==7){
            logoImg=" singlelogo";
            keyTypeWord="的租房买房";
        }else if(d.qtype==8){
            logoImg=" singlelogo";
            resTypeCode="progect";
            resTypeName="项目资源";
            keyTypeWord="的项目资源";
        }else if(d.qtype==9){
            logoImg=" singlelogo";
            keyTypeWord="的人脉资源";
        }else if(d.qtype==10){
            logoImg=" singlelogo";
            resTypeCode="other";
            resTypeName="其他资源";
            keyTypeWord="的其他资源";
        }
        //付费数
        var payNum= d.payCount;
        //有没有钱
        var money="";
        var score="免费";
        if(d.score>0){score="¥ "+parseFloat(d.score)/100;}
        if(d.isredbag==1){score="红包";payNum=""}
        money="<span class='havemy jy"+logoImg+"'><i></i>"+score+"</span>";
        //是不是转换
        var isconvert="";
        if(d.isconvert&&d.isconvert===1){
            //isconvert="(悬赏完成转经验)"
        }
        //经验ID
        var eid="";
        if(d.id){eid=d.id}else if(d.qid){eid=d.qid};

        //我也说说
        var gotoheiexp="<div class='gotoheiexp'>"+keyTypeWord+"</div>";
        //高额
        var isheilogo="";
        if(d.isexphigh===1||d.isexphigh===2){
            isheilogo="<span class='isheighlogo'></span>";
        }
        //经验类型
        var exptypeword="";
        if(d.expTypeInfos&&d.expTypeInfos.length>0){
            $(d.expTypeInfos).each(function(i,e){
                exptypeword+='<span>'+e.name+'</span>    ';
            });
        }else{
            exptypeword='<span>'+resTypeName+'</span>';
        }
        //标题
        var tit=codetoface(d.title);
        var count=0;
        if(d.count){count=d.count;}
        //昵称
        var unick="";
        var datanick="";
        if(d.ishidename===1){
            unick="<a>"+tuijianword+"匿名</a>";
            datanick="匿名";
        }else{
            unick="<a onclick='usergohref(this)' data-uid='"+d.questionUserId+"'>"+tuijianword+"<i class='usernick'> "+d.questionUserNick+realName+"</i></a>";
            datanick=d.questionUserNick+realName;
        }
        //位置
        var location="";
        if(d.pululocation){
            location="<div style='position:relative;margin-bottom:6px;'><img src='img/dingwei.png' style='height:12px;position: absolute;bottom:2px;left:0;'/><span style='color:#999;padding-left:15px;font-size:12px;'>"+d.pululocation+"</span></div>"
        }
        //关键词
        var keywordnor;
        var keyword="<span class='keywordtit'>查看更多有关</span>";
        if(d.keywords){
            keywordnor=d.keywords.split(",");
            for(var a=0;a<keywordnor.length;a++){
                keyword+="<span>"+keywordnor[a]+"</span>";
            }
        }
        //多少字
        var wordNum="";
        if(d.wordcount){wordNum=d.wordcount}
        else if(d.WordCount){wordNum=d.WordCount};
        var des="";
        //不是转发
        if(!d.shareUserId){
            if(!tim){tim="刚刚";}
        }
        //转发
        else if(d.shareUserId&&d.shareUserId.length>0){
            if(d.des){des=codetoface(d.des);}
            var count=0;
            if(d.count){count=d.count;}
            var sharetim=getDateDiff(getDateTimeStamp(d.shareTime.match(/[0-9\-T\:]+/)[0]));
            if(!sharetim){sharetim="刚刚";}
            realName="";
            if(d.shareRealName){realName=" ("+d.shareRealName+")"}
            unick="<a onclick='usergohref(this)' data-uid='"+d.shareUserId+"'><i class='usernick'>"+d.shareUserNick+realName+"</i> 的转发</a>";
            if(d.shareUserAva){
                uimgword="<a onclick='usergohref(this)' data-uid='"+d.shareUserId+"'><img class='profile_photo_img' src='http://42.62.66.198:8003/"+d.shareUserAva+"' onload='showloadimg(this)' style='display:none;'></a>";
            }else{
                uimgword="<a onclick='usergohref(this)' data-uid='"+d.shareUserId+"'><img onclick='gohrefftn(this)' class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'></a>";
            };
            var location="";
            if(d.pululocation){
                location="<div style='position:relative;'><img src='img/dingwei.png' style='height:12px;position: absolute;bottom:2px;left:0;'/><span style='color:#999;padding-left:15px;font-size:12px;'>"+d.pululocation+"</span></div>"
            }

            tim=sharetim;
        };
        if(d.isexphigh===0){
            isheilogo="";
        };
        var thisqtype="";
        if(d.qtype){thisqtype=d.qtype}else{thisqtype=3};
    //    $("#explist .addlistplace").append("<div class='pagedlist_item shareexperience' data-money='"+d.score+"' onclick='hrefgo(this)' data-page='#mainbody' data-euser='"+d.questionUserId+"' data-href='shareexppage.html?eid="+eid+"#fromuser="+id+"' data-shareuserid='"+d.shareUserId+"'><div class='feed_item feed_type_question'><div class='borderbox'>"+"<div class='ContentHeader'><div class='photo_info_layout size_small'><div class='photo_wrapper'><div class='photo'>"+uimgword+"</div></div><div class='info_wrapper'><span class='feed_item_answer_user'> <span class='user'>"+unick+"</span>"+money+"</span><div class='ContentFooter'><span style='color:#598abf;'>"+exptypeword+"</span>"+tim+"</div></div></div></div>"+"<div class='info_wrapper' style='margin-bottom:7px;'> <div class='info'> <span class='feed_item_answer_user'>"+des+"</span> </div> </div> <h2><a class='question_link'>"+isconvert+tit+"("+wordNum+"字)"+haveimg+isheilogo+"</a></h2><div class='ActionBar Question'>"+location+"<div class='question_topics_container' onclick='gotoheiexp(this)' data-qtype='"+thisqtype+"' data-keyword="+eid+"><div class='QuestionTopics has_topics'>"+keyword+gotoheiexp+"</div></div><div class='action_bar_inner'><div class='action_item'> <a class='ReadMoreActionItem'>"+count+" 浏览 · "+payNum+ d.webchatCount+" 转发到微信</a></div></div></div>"+"</div></div></div>")

        /*newStyle*/
        if(d.pululocation){
            location="<p style='position:relative;margin-bottom:4px;margin-top:8px;'><p class='locationLogo' style='position: absolute;bottom:11px;left:0;'></p><span style='color:#999;padding-left:15px;font-size:13px;'>"+d.pululocation+"</span></div>"
        };
        var newKeyWord="<span class='newKeyWord' onclick='gotoheiexp(this)' data-qtype='"+thisqtype+"' data-keyword='"+eid+"'>"+d.keywords.split(",").join("|")+"|    </span>";
        if(d.isredbag===1){score="红包";payNum=""}else{
            payNum="&nbsp;&nbsp;&nbsp;&nbsp;<span class='payNum'></span>"+payNum;
        }
        $("#explist .addlistplace").append("<div class='pagedlist_item shareexperience' onclick='hrefgo(this)' data-nick='"+datanick+"' data-euser='"+d.questionUserId+"' data-href='shareexppage.html?eid="+eid+"#fromuser="+id+"' data-shareuserid='"+d.shareUserId+"'><div class='feed_item feed_type_question'><div class='borderbox'>"+"<div class='ContentHeader'><div class='photo_info_layout size_small'><div class='photo_wrapper'><div class='photo'>"+uimgword+"</div></div><div class='info_wrapper'><span class='feed_item_answer_user'> <span class='user'>"+unick+"</span>"+money+"</span><div class='ContentFooter'>"+exptypeword+"</div></div></div></div>"+"<div class='info_wrapper' style='margin-bottom:7px;'> <div class='info'> <span class='feed_item_answer_user'>"+des+"</span> </div> </div> <h1>"+newKeyWord+"<a class='question_link'>"+isconvert+tit+"("+wordNum+"字)"+haveimg+isheilogo+"</a></h1><div class='ActionBar Question'><div class='action_bar_inner'><div class='action_item'> <a class='ReadMoreActionItem'><span class='browseNum'></span>"+count+payNum+"&nbsp;&nbsp;&nbsp;&nbsp;<span class='sendNum'></span>"+d.webchatCount+"</a><a class='rt'>"+tim+"</a></div></div>"+location+"</div>"+"</div></div></div>")
    };
};

//加载经验
function getExpTypenote(currentIndex,pageSize,sendurllot,sendurllat){
    $.ajax({
        type:"get",
        url:expByTypeUrl+"?userId="+$.cookie("MYID")+"&currentIndex="+currentIndex+"&pageSize="+pageSize+"&etypeId="+$.cookie("selectType")+sendurllot+sendurllat,
        complete:function(XHR, TS){
            if(XHR.status==0){
                window.location.reload();
            }
        },
        success:function(d){
            readyover=0;
            if(d.Message=="没有数据"||!d.Data||d.Data.length==0){
                $("#waiting1").css("display","none");
                $("#nonews1").css("display","block");
            }
            else{
                if(d.Data.length<pageSize){
                    $("#waiting1").css("display","none");
                    $("#nonews1").css("display","block");
                }
                for(var i=0;i< d.Data.length;i++){
                    jy(d.Data[i]);
                }
                //页面定位
                if($.cookie("jycurrentIndex")&&/[0-9]/.test($.cookie("jycurrentIndex"))){
                    if(/^[0-9]+$/.test($.cookie("jyscrollTop"))){
                        var toTop= parseInt($.cookie("jyscrollTop"));
                        $(window).scrollTop(toTop);
                        //还原参数
                        pageSize=15;
                        currentIndex=parseInt($.cookie("jycurrentIndex"));
                        //清除参数
                        $.cookie("jyscrollTop","");
                        $.cookie("jycurrentIndex","");
                    }
                }
            }
        }
    })
}
//加载单身...
function getSTypenote(urlLoca){
    $.ajax({
        type:"get",
        url:urlLoca+$.cookie("MYID")+"&currentIndex="+currentIndex+"&pageSize="+pageSize+"&type=1",
        success:function(d){
            readyover=0;
            if(d.Message=="没有数据"||!d.Data||d.Data.length==0){
                $("#waiting1").css("display","none");
                $("#nonews1").css("display","block");
            }
            else{
                if(d.Data.length<pageSize){
                    $("#waiting1").css("display","none");
                    $("#nonews1").css("display","block");
                }
                console.log(d);
                for(var i=0;i< d.Data.length;i++){
                    jy(d.Data[i]);
                }
                //页面定位
                if($.cookie("jycurrentIndex")&&/[0-9]/.test($.cookie("jycurrentIndex"))){
                    if(/^[0-9]+$/.test($.cookie("jyscrollTop"))){
                        var toTop= parseInt($.cookie("jyscrollTop"));
                        $(window).scrollTop(toTop);
                        //还原参数
                        pageSize=15;
                        currentIndex=parseInt($.cookie("jycurrentIndex"));
                        //清除参数
                        $.cookie("jyscrollTop","");
                        $.cookie("jycurrentIndex","");
                    }
                }
            }
        }
    })
}
/*
 调用接口
 */
function getallnote(currentIndex,pageSize){
    //公用参数 页面加载类型
    if(!$.cookie("selectType")){ //获取selectType
        var typeId=location.href.match(/type=[0-9]+/)[0].split("=")[1];
        $.cookie("selectType",typeId);
    }
    var sendurllot="",sendurllat="";
    if($.cookie("selectType")==22){sendurllot=urllot;sendurllat=urllat;}
    readyover=1;
    //判断类型 经验/单身...
    if(/^[0-9]+$/.test($.cookie("selectType"))){
        //纯数字 为经验的类型
        getExpTypenote(currentIndex,pageSize,sendurllot,sendurllat);
    }
    else if(/^[a-zA-Z]+$/.test($.cookie("selectType"))){
        var urlLoca=getAllSingle;//接口默认为单身
        if($.cookie("selectType")=="work"){
            urlLoca=getAllWork;
        }
        else if($.cookie("selectType")=="house"){
            urlLoca=getAllHouse;
        }
        else if($.cookie("selectType")=="progect"){
            urlLoca=getAllProgect;
        }
        else if($.cookie("selectType")=="resource"){
            urlLoca=getAllResource;
        }
        else if($.cookie("selectType")=="other"){
            urlLoca=getAllOther;
        }
        getSTypenote(urlLoca);
    }
}

//经验数据
if(!id){
    location.href="http://www.pulu.com/weixin/login.html"
}
if($.cookie("jycurrentIndex")){
    if(!$.cookie("selectType")){
        var typeId=location.href.match(/type=[0-9]+/)[0].split("=")[1];
        $.cookie("selectType",typeId);
    }
    $("#explist div.addlistplace div").remove();
    var pagelist=document.getElementsByClassName("HomeMainFeed");
    var navlist=document.getElementsByClassName("HeaderSwitcherItem");
    readyover=1;//控制页面滚动
    //判断页码是否为数字
    if(/[0-9]/.test($.cookie("jycurrentIndex"))){
        pageSize=parseFloat($.cookie("jycurrentIndex"))*pageSize;
        currentIndex=1;
    } else{
        pageSize=15;
        currentIndex=1;
    }
    //经验
    if(/^[0-9]+$/.test($.cookie("selectType"))){
        //附近
        if($.cookie("selectType")==22){
            if($.cookie("pululot")){
                urllot="&lot="+$.cookie("pululot");
                urllat="&lat="+$.cookie("pululat");
                getallnote(currentIndex,pageSize);
            }else{
                mapftn();
            }
        }else{
            getallnote(1,pageSize);
        }
    }
    //单身..."single","work","house","progect","resource","other"
    else if(/^[a-zA-Z]+$/.test($.cookie("selectType"))){
        var urlLoca=getAllSingle;//接口默认为单身
        if($.cookie("selectType")=="work"){
            urlLoca=getAllWork;
        }
        else if($.cookie("selectType")=="house"){
            urlLoca=getAllHouse;
        }
        else if($.cookie("selectType")=="progect"){
            urlLoca=getAllProgect;
        }
        else if($.cookie("selectType")=="resource"){
            urlLoca=getAllResource;
        }
        else if($.cookie("selectType")=="other"){
            urlLoca=getAllOther;
        }
        getSTypenote(urlLoca);
    }
}
else{
    if(id){
        //经验
        if(/type=[0-9]+/.test(location.href)){
            //附近
            if(!$.cookie("selectType")){
                var typeId=location.href.match(/type=[0-9]+/)[0].split("=")[1];
                $.cookie("selectType",typeId);
            };
            if($.cookie("selectType")==22){
                if($.cookie("pululot")){
                    urllot="&lot="+$.cookie("pululot");
                    urllat="&lat="+$.cookie("pululat");
                    getallnote(currentIndex,pageSize);
                }else{
                    mapftn();
                }
            }else{
                getallnote(currentIndex,pageSize);
            }
        }
        //单身...
        else if(/type=[a-zA-Z]+/.test(location.href)){
            if(!$.cookie("selectType")){
                var typeId=location.href.match(/type=[a-zA-Z]+/)[0].split("=")[1];
                $.cookie("selectType",typeId);
            };
            var urlLoca=getAllSingle;//接口默认为单身
            if($.cookie("selectType")=="work"){
                urlLoca=getAllWork;
            }
            else if($.cookie("selectType")=="house"){
                urlLoca=getAllHouse;
            }
            else if($.cookie("selectType")=="progect"){
                urlLoca=getAllProgect;
            }
            else if($.cookie("selectType")=="resource"){
                urlLoca=getAllResource;
            }
            else if($.cookie("selectType")=="other"){
                urlLoca=getAllOther;
            }
            getSTypenote(urlLoca);
        }
    }
}
/*
 切换类型
 */
$(".title").click(function(){
    $("#page_title .toparr").toggle();
    $("#page_title .select").toggle();
});
$("#page_title .select").delegate(".option","click",function(i){
    //取消冒泡
    var e=arguments.callee.caller.arguments[0]||event;
    if (e && e.stopPropagation) {
        e.stopPropagation();
    } else if (window.event) {
        window.event.cancelBubble = true;
    }
    //加载完成才可以切换
    //console.log(readyover);
    if(readyover==0){
        var thisid=i.target.dataset.num;
        $.cookie("selectType",thisid);
        $("#page_title .title").html(i.target.innerHTML);
        $("#page_title .option").attr("class","option");
        $(i.target).attr("class","option active");
        $("#page_title .select").hide();
        $("#page_title .toparr").hide();
        ////数据还原
        $("#waiting1").css("display","block");
        $("#nonews1").css("display","none");
        $("#nonews").css("display","none");
        pageSize=15;
        currentIndex=1;
        //页面重新加载
        $(window).scrollTop(0);
        $("#explist .addlistplace div").remove();//清空页面
        getallnote(currentIndex,pageSize);
    }
});
/*
 滚动
 */
$(window).scroll(function(){
    $(".quicklist").css("display","none");
    $("#refreshbtn").css("display","block");
    var mainheight=$(".home_feed").height();
    var windowheight=$(window).height();
    var what=$(".home_feed").offset().top;
    var chajuli=$(".home_feed").offset().top - $(window).scrollTop();
    var cz=windowheight-mainheight+50;
    if(chajuli<cz&&readyover===0){
        currentIndex++;
        readyover=1;
        getallnote(currentIndex,pageSize);
    }
});